﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EzDesk.Apps.ServiceImpl.Attendance.Repositories.Interface;
using EzDesk.Apps.Model.Attendance;

namespace EzDesk.Apps.ServiceImpl.Attendance.Repositories
{
    public class LeaveTypeRepository : ILeaveTypeRepository
    {
        EzDeskAttendanceDataContext _db;

        public LeaveTypeRepository(EzDeskAttendanceDataContext db)
        {
            this._db = db;
        }


        public Guid Add(LeaveType model, bool saveChanges)
        {

            throw new NotImplementedException();
        }

        public LeaveType GetById(Guid id)
        {
            return _db.ez_LeaveTypes
                .Where(p => p.LeaveTypeId == id)
                .Select(
                p => new LeaveType()
                {
                    Id = p.LeaveTypeId,
                    IsForWork = p.IsForWork,
                    LeaveTypeName = p.LeaveName,
                    Remark = p.Remark
                })
                .Single();
        }

        public IQueryable<LeaveType> GetAll()
        {
            return _db.ez_LeaveTypes
                .OrderBy(p=>p.OrderValue)
                .Select(
                p => new LeaveType()
                {
                    Id = p.LeaveTypeId,
                    IsForWork = p.IsForWork,
                    LeaveTypeName = p.LeaveName,
                    Remark = p.Remark
                });
        }

        public void Delete(Guid id, bool saveChanges)
        {
            throw new NotImplementedException();
        }

        public void Update(LeaveType model, bool saveChanges)
        {
            throw new NotImplementedException();
        }

        public void SaveChanges()
        {
            _db.SubmitChanges();
        }
    }
}
